import { defineStore } from "pinia";
import { AppState } from "@/stores/interface";
import piniaPersistConfig from "@/config/piniaPersist";
import { SYS_CONFIG } from "../mutation-types";
import ACrypto from "@/utils/crypto";
import vueAxios from "@/api/index";
export const useAppStore = defineStore({
  id: "app",
  state: (): AppState => ({
    LoadingConfig: {
      contentLoading: false,
      contentTip: "正在加载中..."
    },
    hideRouter: [],
    sysConfig: {}, //系统参数
    urlBorrrow: []
  }),
  getters: {},
  actions: {
    setHideRouter(data: any[]) {
      this.hideRouter = data;
    },
    // 获取全局参数
    async setSysConfigData() {
      await vueAxios.get("Master_Base_SysConfig/Get", { order: "Sys_Order asc" }, { noLoading: true }).then((res: any) => {
        this.sysConfig = res.List;
        ACrypto.setSS(this.sysConfig, SYS_CONFIG);
      });
    },
    // 设置urlborrow
    setBorrrowData(data: any[]) {
      let newElements = data.filter(item => !this.urlBorrrow.map(v => v.AI_ID).includes(item.AI_ID));
      // 将新元素添加到 arr1 中
      this.urlBorrrow = this.urlBorrrow.concat(newElements);
    },
    // 移除urlborrow
    delBorrrowData(data: object) {
      this.urlBorrrow = this.urlBorrrow.filter(item => item.AI_ID !== data.AI_ID);
    }
  },
  persist: piniaPersistConfig("app", ["hideRouter"])
});
